package com.atguigu.lease.web.admin.shcedule;

import com.atguigu.lease.model.entity.LeaseAgreement;
import com.atguigu.lease.model.enums.LeaseStatus;
import com.atguigu.lease.web.admin.service.LeaseAgreementService;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author 李俊伟
 * @date 2024/12/24 19:06
 */
// 编写定时逻辑
@Component
public class ScheduledTasks {
    @Autowired
    private LeaseAgreementService leaseAgreementService;

//    @Scheduled(cron = "0/5 * * * * *")
    public void checkLeaseAgreement(){
        LambdaUpdateWrapper<LeaseAgreement> updateWrapper = new LambdaUpdateWrapper<>();
//        Date nowDate = new Date();
        // 修改租约状态条件： 租约结束日期 小于 当前日期
        updateWrapper.le(LeaseAgreement::getLeaseEndDate, new Date());

        // 租约状态status（2，5）--出租状态
        updateWrapper.in(LeaseAgreement::getStatus, LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING);

        // 修改租约为已经到期
        updateWrapper.set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED);
        leaseAgreementService.update(updateWrapper);

    }

}